#!/usr/bin/env python
# ------------------------------------------------------------------------------
#
# Rna
#
# Copyright (c) 2012 Fernando Garcia Huerta
# nanomuelle@gmail.com
#
#    This file is part of SimCell
#
#    SimCell is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    SimCell is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with SimAnim.  If not, see <http://www.gnu.org/licenses/>.
#
# ------------------------------------------------------------------------------

import random
from simcell.genetic.nucleotide import NucleotideFactory

class Rna:

    NUCLEOTIDES = [NucleotideFactory.A, NucleotideFactory.U]
    
    @classmethod
    def generateRandomRna(cls, num_nucleotides):
        rna = Rna()
        for x in range(num_nucleotides):
            rna.addNucleotid(NucleotidFactory.getRandom())
        return rna

    def __init__(self):
        self.strand = []
        self.composition = {'a':0.0, 'u':0.0}

    def __str__(self):
        repr  = "length:%d a:%d u:%d" % (len(self.strand), self.composition['a'], self.composition['u'])
        return repr
        
    def __repr__(self):
        repr  = str(self) + "\n"
        repr += "5'" + "".join(map(str, self.strand)) + "'3\n"
        return repr
    
    def addNucleotide(self, nucleotide):
        # TODO: introduce copy errors here?
        self.strand.append(nucleotide)
        self.composition[nucleotide.name] += 1